Skip to content

✨ Add tiered logging and HTTP request helper#31

Merged
Tairesh merged 2 commits into
mainfrom
feat/logging
May 7, 2026
Merged

✨ Add tiered logging and HTTP request helper#31
Tairesh merged 2 commits into
mainfrom
feat/logging

Conversation

@Tairesh

@Tairesh Tairesh commented May 7, 2026

Copy link
Copy Markdown
Owner

Summary

  • New logging module with warn! / info! / debug! macros driven by the existing verbose: u8 flag (0=silent, 1=warn, 2=info, 3=debug). Zero overhead at the default level — macros short-circuit before format! and the HTTP helper skips timing/body reads. No new crate dependencies.
  • New crate::weather::http::get_json centralizes HTTP send + JSON parse for every provider and the OpenUV helper, emitting one INFO line per request (provider, operation, status, latency) and full URLs + truncated bodies at DEBUG.
  • Live mode buffers logs in a 1000-line ring buffer and flushes them to stderr via an RAII CaptureGuard after the alt-screen is restored, so the UI stays clean during the session and nothing is lost on q/Esc/Ctrl+C or panic.
  • Replaces ad-hoc eprintln! in app.rs and openuv.rs, dedupes missing-translation warnings (one per key per process), and adds cache hit/miss + enrichment-action info logs.
  • Bug fix: a transient OpenUV failure (transport/parse error) no longer aborts the whole weather fetch. UV index is silently omitted with a -v warning; the rest of the data still displays. enrich now returns () since it can no longer fail.

CLI usage: rustormy -c London -v (warnings), -vv (request summaries + cache hits/misses), -vvv (full URLs + bodies). README and CHANGELOG updated with the user-visible behavior.

Test plan

  • just check — fmt + cargo check + 158 tests + clippy pedantic, all green
  • Default verbosity: rustormy -c <city> 2>/tmp/err/tmp/err is empty
  • Each level produces expected output (-v/-vv/-vvv) with the right info; INFO has no URLs/keys, DEBUG has both
  • Provider fallback: temporarily bad TomorrowIo key triggers [WARN] Provider TomorrowIo failed: ... then succeeds via next provider
  • OpenUV fail: bad open_uv key triggers [WARN] OpenUV API error: ... and the rest of the weather still renders
  • Missing translation: 3 calls with the same missing key produce exactly one WARN (HashSet dedup verified)
  • Cache miss → hit transition: first run logs cache miss, second run logs cache hit and skips geocoding
  • JSON output stays valid: rustormy -c <city> -o json -vv 2>/dev/null | jq . parses successfully
  • Capture buffer overflow marker ((capture buffer overflow: N earlier lines dropped)) appears when ring buffer wraps
  • Performance: time comparison between verbose=0 and verbose=3 shows no measurable difference (HTTP latency dominates)

- New `logging` module with `warn!`/`info!`/`debug!` macros driven by
  the existing `verbose: u8` flag (0=silent, 1=warn, 2=info, 3=debug).
  Zero-overhead at default verbosity: macros short-circuit before
  `format!` and the HTTP helper skips timing/body reads.
- Live mode buffers logs in a 1000-line ring buffer and flushes them to
  stderr via an RAII `CaptureGuard` after the alt-screen is restored, so
  log lines never corrupt the UI.
- New `weather::http::get_json` centralizes HTTP send + JSON parse with
  request observability (INFO: provider/op/status/duration; DEBUG: full
  URL and truncated response body). All seven providers and the OpenUV
  helper migrated onto it.
- Replace ad-hoc `eprintln!` in `app.rs` and `openuv.rs` with `warn!`.
  Add deduped missing-translation warnings (one per key per process)
  and cache hit/miss + enrich-action info logs.
- Fix latent bug: a transient OpenUV failure no longer aborts the
  weather fetch; the error is logged as a warning and `uv_index` stays
  `None`. `enrich` now returns `()` since it can no longer fail.
- README and CHANGELOG updated with `-v`/`-vv`/`-vvv` usage and the new
  user-visible behavior.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a tiered diagnostic logging system and refactors HTTP request handling across all weather providers to use a centralized helper with integrated logging. It also improves error handling for OpenUV and adds deduplicated logging for missing translation keys. The feedback highlights several uses of 'let chains' in src/logging.rs and src/weather/http.rs, which is an unstable Rust feature; these should be refactored into nested if let statements to maintain compatibility with the stable compiler.

Comment thread src/logging.rs
Comment thread src/logging.rs
Comment thread src/logging.rs
Comment thread src/logging.rs
Comment thread src/weather/http.rs
@Tairesh Tairesh merged commit c03f0b5 into main May 7, 2026
5 checks passed
@Tairesh Tairesh deleted the feat/logging branch May 7, 2026 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant